package view;

import action.GoddessAction;
import model.Goddess;

import java.util.List;
import java.util.Scanner;

public class View {

    public static final String OPERATION_EXIT = "EXIT";
    public static final String OPERATION_ADD = "ADD";
    public static final String OPERATION_BREAK = "BREAK";
    public static final String OPERATION_QUERY = "QUERY";

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String operationFlag = null;
        int step = 0;
        Goddess goddess = null;
        GoddessAction goddessAction = new GoddessAction();
        while (scanner.hasNext()){
            String in = scanner.next().toString();
            if(OPERATION_EXIT.equals(in.toUpperCase())){
                System.out.println("已退出");
                break;
            }else if(OPERATION_ADD.equals(in.toUpperCase()) || OPERATION_ADD.equals(operationFlag)){
                if(step == 0 ){
                    System.out.println("开始添加");
                    operationFlag = OPERATION_ADD;
                    goddess = new Goddess();
                    System.out.println("请输入姓名");
                }else if(step == 1){
                    goddess.setUserName(in);
                    System.out.println("请输入年龄");
                }else if(step == 2){
                    goddess.setAge(Integer.valueOf(in));
                    System.out.println("请输入性别，0为男性，1为女性");
                }else if(step == 3){
                    goddess.setSex(Integer.valueOf(in));
                    System.out.println("请输入邮箱");
                }else if(step == 4){
                    goddess.setEmail(in);
                    if(goddessAction.addGoddess(goddess)){
                        System.out.println("添加成功");
                    }else {
                        System.out.println("添加失败");
                    }
                    step = 0;
                    operationFlag = null;
                }
                step ++;
            }else if(OPERATION_QUERY.equals(in.toUpperCase())){
                List<Goddess> list = goddessAction.query(null);
                if(list!=null){
                    for (Goddess goddess1 : list) {
                        System.out.println(goddess1.getUserName() + " " + goddess1.getEmail());
                    }
                }
            }
        }
    }

}
